<template>
  <div>
    <div id="gs-slide" class="gs-slide" ref="gsSlide">
      <div id="slideGroup" class="slide-group" ref="slideGroup">
        <slot></slot>
      </div>
      <div v-if="showDot" class="dots">
        <span
          class="dot"
          :class="{active: currentPageIndex === index}"
          v-for="{item, index} in dots"
          :key="index"
        ></span>
      </div>
    </div>
  </div>
</template>

<script>
import GScroll from 'src'
export default {
  name: 'GsSlide',
  props: {
    autoPlay: {
      type: Boolean,
      default: true
    },
    loop: {
      type: Boolean,
      default: true
    },
    interval: {
      type: Number,
      default: 3000
    },
    threshold: {
      type: Number,
      default: 50
    },
    speed: {
      type: Number,
      default: 400
    },
    showDot: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      dots: [],
      currentPageIndex: 0
    }
  },
  mounted () {},
  methods: {
    init () {
      this.scroll = new GScroll('gs-slide', {
        scrollX: true,
        scrollY: false,
        snap: {
          autoPlay: true,
          loop: this.loop,
          interval: this.interval,
          threshold: this.threshold,
          speed: this.speed
        }
      })
    }
  }
}
</script>

<style lang="scss">
.gs-slide {
  .slide-group {
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    .slide-item {
      float: left;
      box-sizing: border-box;
      overflow: hidden;
      text-align: center;
      a {
        display: block;
        width: 100%;
        overflow: hidden;
        text-decoration: none;
      }
      img {
        display: block;
        width: 100%;
      }
    }
    .dots {
      position: absolute;
      right: 0;
      left: 0;
      bottom: 12px;
      transform: translateZ(1px);
      text-align: center;
      font-size: 0;
      .dot {
        display: inline-block;
        margin: 0 4px;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #ccc;
        &.active {
          width: 20px;
          border-radius: 5px;
          background: white;
        }
      }
    }
  }
}
</style>
